(function(){BX.namespace("BX.UI");if(BX.UI.SidePanelWrapper){return}function t(t){}t.prototype.init=function(t){this.container=BX(t.containerId);this.isCloseAfterSave=t.isCloseAfterSave||false;this.isReloadGridAfterSave=t.isReloadGridAfterSave||false;this.isReloadPageAfterSave=t.isReloadPageAfterSave||false;this.useLinkTargetsReplacing=t.useLinkTargetsReplacing||false;this.notification=t.notification||{};if(t.title&&t.title.selector&&t.title.defaultTitle){var i=this.container.querySelector(t.title.selector);var n=i.querySelector('input[type="text"]');if(n){i.style.display="none";e.init({dataContainer:i,dataNode:n,defaultTitle:t.title.defaultTitle})}}if(this.hasSidePanel()){parent.BX.addCustomEvent(parent.BX.SidePanel.Instance.getTopSlider(),"SidePanel.Slider:onReload",this.onSidePanelReload.bind(this))}if(this.useLinkTargetsReplacing){this.initLinkTargetsReplacing()}this.isNotificationWillShowed()};t.prototype.initLinkTargetsReplacing=function(){this.replaceLinkTargets();if(!window.MutationObserver){return}var t=new MutationObserver(this.domMutationHandler.bind(this));t.observe(this.container,{childList:true,subtree:true})};t.prototype.domMutationHandler=function(t){t.forEach(function(t){for(var e=0;e<t.addedNodes.length;++e){var i=t.addedNodes.item(e);if(!i){continue}this.replaceLinkTargets(i)}},this)};t.prototype.replaceLinkTargets=function(t){if(!t){t=document.body}var e;if(t.tagName==="A"){e=[t]}else{e=BX.convert.nodeListToArray(t.querySelectorAll("a"))}if(e.length===0){return}BX.convert.nodeListToArray(e).filter(function(t){return!t.target}).forEach(function(t){t.target="_top"})};t.prototype.hasSidePanel=function(){return parent&&parent.BX&&parent.BX.SidePanel};t.prototype.onSidePanelReload=function(){if(!this.hasSidePanel()){return}if(this.isReloadGridAfterSave){this.reloadGridOnParentPage()}if(this.isCloseAfterSave){var t;if(this.isNotificationWillShowed()){t=this.showNotification.bind(this)}else if(this.isReloadPageAfterSave){t=function(){parent.window.location.reload()}}parent.BX.SidePanel.Instance.close(false,t)}};t.prototype.isNotificationWillShowed=function(){if(!this.notification.content||!parent.BX){return false}if(!this.hasSidePanel()){return false}if(this.notification.showAlways){return true}if(this.sidePanelParam()===true){return true}var t=window.location.search.substr(1).split("&").filter(function(t){return t==="notifyAfterSave=Y"}).length>0;this.sidePanelParam(t);return t};t.prototype.sidePanelParam=function(t){var e=parent.BX.SidePanel.Instance.getTopSlider();if(!e){return null}var i=e.getData();if(typeof t==="undefined"){return i.get("isNotificationWillShowed")}else{return i.set("isNotificationWillShowed",t)}};t.prototype.showNotification=function(){if(!parent.BX.UI||!parent.BX.UI.Notification){return}parent.BX.UI.Notification.Center.notify(this.notification);this.sidePanelParam(null)};t.prototype.reloadGridOnParentPage=function(){var t=BX.type.isString(this.isReloadGridAfterSave)?this.isReloadGridAfterSave:null;if(!parent.BX.Main||!parent.BX.Main.gridManager){return}if(!t&&parent.BX.Main.gridManager.data){var e=parent.BX.Main.gridManager.data;t=e.length>0?e[0].id:null}if(!t){return}var i=parent.BX.Main.gridManager.getById(t);if(!i){return}i.instance.reload()};var e={isInit:false,init:function(t){this.dataNode=t.dataNode;this.titleNode=BX("pagetitle");this.inputNode=BX("pagetitle_input");this.buttonNode=BX("pagetitle_edit");this.initialTitle=this.titleNode.textContent;this.defaultTitle=t.defaultTitle;BX.bind(this.dataNode,"bxchange",this.onDataNodeChange.bind(this));BX.bind(this.buttonNode,"click",this.startEdit.bind(this));BX.bind(this.inputNode,"keyup",this.onKeyUp.bind(this));BX.bind(this.inputNode,"blur",this.endEdit.bind(this));this.isInit=true;if(!t.disabled){this.enable()}if(!this.dataNode.value){this.dataNode.value=this.defaultTitle}},enable:function(t){t=t||false;if(!this.isInit){return}this.changeDisplay(this.buttonNode,!t);this.titleNode.textContent=!t?this.dataNode.value?this.dataNode.value:this.defaultTitle:this.initialTitle},disable:function(){this.enable(true)},onDataNodeChange:function(){this.titleNode.textContent=this.dataNode.value},onKeyUp:function(t){t=t||window.event;if(t.keyCode===10||t.keyCode===13){this.endEdit();t.preventDefault();return false}},getTitle:function(){var t=this.dataNode.value;if(!t){t=this.titleNode.textContent}return t},startEdit:function(){this.inputNode.value=this.getTitle();this.changeDisplay(this.titleNode,false);this.changeDisplay(this.buttonNode,false);this.changeDisplay(this.inputNode,true);this.inputNode.focus()},endEdit:function(){this.dataNode.value=this.inputNode.value;this.titleNode.textContent=this.inputNode.value;this.changeDisplay(this.inputNode,false);this.changeDisplay(this.buttonNode,true);this.changeDisplay(this.titleNode,true)},changeDisplay:function(t,e){return t.style.display=e?"":"none"}};BX.UI.SidePanelWrapper=new t})();